package chapter.tenth.item71;

import com.google.protobuf.FieldType;

public class InstanceFieldLazyInit {
	
	private volatile FieldType field;
	
	FieldType getField(){
		FieldType result = field;
		if(result == null){
			synchronized (this) {
				result = field;
				if(result == null){
					field = result = computeFieldValue();
				}
			}
		}
		return result;
	}

	private FieldType computeFieldValue() {
		return FieldType.BOOL;
	}
	
	public static void main(String[] args) {
		InstanceFieldLazyInit lazy = new InstanceFieldLazyInit();
		System.out.println(lazy.getField());
	}
}
